<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#222"><meta name="generator" content="Hexo 7.3.0">

  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32.ico">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16.ico">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">



<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css" integrity="sha256-wiz7ZSCn/btzhjKDQBms9Hx4sSeUYsDrTLg7roPstac=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.1.1/animate.min.css" integrity="sha256-PR7ttpcvz8qrF57fur/yAx1qXMFJeJFiA6pSzWi0OIE=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fancyapps-ui/5.0.28/fancybox/fancybox.css" integrity="sha256-6cQIC71/iBIYXFK+0RHAvwmjwWzkWd+r7v/BX3/vZDc=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/pace/1.2.4/themes/green/pace-theme-minimal.css">
  <script src="https://cdnjs.cloudflare.com/ajax/libs/pace/1.2.4/pace.min.js" integrity="sha256-gqd7YTjg/BtfqWSwsJOvndl0Bxc8gFImLEkXQT8+qj0=" crossorigin="anonymous"></script>

<script class="next-config" data-name="main" type="application/json">{"hostname":"sumumm.github.io","root":"/","images":"/images","scheme":"Gemini","darkmode":false,"version":"8.19.2","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":{"enable":true,"style":"mac"},"fold":{"enable":true,"height":300},"bookmark":{"enable":false,"color":"#222","save":"auto"},"mediumzoom":false,"lazyload":true,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"stickytabs":false,"motion":{"enable":true,"async":true,"transition":{"menu_item":"fadeInDown","post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"},"path":"/search.xml","localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false}}</script><script src="/js/config.js"></script>

    <meta name="description" content="本文主要是SQLite数据库的数据类型、运算符和表达式相关笔记，若笔记中有错误或者不合适的地方，欢迎批评指正😃。">
<meta property="og:type" content="article">
<meta property="og:title" content="LV07-02-SQLite-数据类型、运算符和表达式">
<meta property="og:url" content="https://sumumm.github.io/post/aaf421eb.html">
<meta property="og:site_name" content="苏木">
<meta property="og:description" content="本文主要是SQLite数据库的数据类型、运算符和表达式相关笔记，若笔记中有错误或者不合适的地方，欢迎批评指正😃。">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2023-07-03T13:30:25.000Z">
<meta property="article:modified_time" content="2025-06-13T16:25:57.000Z">
<meta property="article:author" content="苏木">
<meta property="article:tag" content="LV07-SQLite">
<meta name="twitter:card" content="summary">


<link rel="canonical" href="https://sumumm.github.io/post/aaf421eb.html">



<script class="next-config" data-name="page" type="application/json">{"sidebar":"","isHome":false,"isPost":true,"lang":"zh-CN","comments":true,"permalink":"https://sumumm.github.io/post/aaf421eb.html","path":"post/aaf421eb.html","title":"LV07-02-SQLite-数据类型、运算符和表达式"}</script>

<script class="next-config" data-name="calendar" type="application/json">""</script>
<title>LV07-02-SQLite-数据类型、运算符和表达式 | 苏木</title>
  








    <script src="/js/browser_tools_disable.js"></script>

  <noscript>
    <link rel="stylesheet" href="/css/noscript.css">
  </noscript>
<!-- hexo injector head_end start --><link rel="stylesheet" href="https://unpkg.com/hexo-next-tags-plus@latest/lib/tag_plus.css" media="defer" onload="this.media='all'"><!-- hexo injector head_end end --></head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <div class="column">
      <header class="header" itemscope itemtype="http://schema.org/WPHeader"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <p class="site-title">苏木</p>
      <i class="logo-line"></i>
    </a>
      <p class="site-subtitle" itemprop="description">我的学习之路</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger" aria-label="搜索" role="button">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu"><li class="menu-item menu-item-home"><a href="/" rel="section"><i class="fa fa-home fa-fw"></i>苏木的家</a></li><li class="menu-item menu-item-categories"><a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类页<span class="badge">42</span></a></li><li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档页<span class="badge">673</span></a></li><li class="menu-item menu-item-flink"><a href="/flink/" rel="section"><i class="fa fa-link fa-fw"></i>友人帐</a></li><li class="menu-item menu-item-about"><a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于我</a></li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup"><div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off" maxlength="80"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close" role="button">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div class="search-result-container no-result">
  <div class="search-result-icon">
    <i class="fa fa-spinner fa-pulse fa-5x"></i>
  </div>
</div>

    </div>
  </div>

</header>
        
  
  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%B8%80%E3%80%81%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B"><span class="nav-text">一、数据类型</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-SQLite-%E5%AD%98%E5%82%A8%E7%B1%BB"><span class="nav-text">1. SQLite 存储类</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-SQLite-%E4%BA%B2%E5%92%8C-Affinity-%E7%B1%BB%E5%9E%8B"><span class="nav-text">2. SQLite 亲和(Affinity)类型</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#2-1-%E4%BB%80%E4%B9%88%E6%98%AF%E4%BA%B2%E5%92%8C%E7%B1%BB%E5%9E%8B%EF%BC%9F"><span class="nav-text">2.1 什么是亲和类型？</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-2-SQLite%E6%94%AF%E6%8C%81%E7%9A%84%E4%BA%B2%E5%92%8C%E7%B1%BB%E5%9E%8B"><span class="nav-text">2.2 SQLite支持的亲和类型</span></a></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%BA%8C%E3%80%81%E8%BF%90%E7%AE%97%E7%AC%A6"><span class="nav-text">二、运算符</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E7%AE%97%E6%9C%AF%E8%BF%90%E7%AE%97%E7%AC%A6"><span class="nav-text">1. 算术运算符</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-%E6%AF%94%E8%BE%83%E8%BF%90%E7%AE%97%E7%AC%A6"><span class="nav-text">2. 比较运算符</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-%E9%80%BB%E8%BE%91%E8%BF%90%E7%AE%97%E7%AC%A6"><span class="nav-text">3. 逻辑运算符</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-%E4%BD%8D%E8%BF%90%E7%AE%97%E7%AC%A6"><span class="nav-text">4. 位运算符</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#4-1-%E4%B8%80%E4%B8%AA%E7%9C%9F%E5%80%BC%E8%A1%A8"><span class="nav-text">4.1 一个真值表</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-2-%E8%BF%90%E7%AE%97%E7%AC%A6%E8%AF%B4%E6%98%8E"><span class="nav-text">4.2 运算符说明</span></a></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%B8%89%E3%80%81%E8%A1%A8%E8%BE%BE%E5%BC%8F"><span class="nav-text">三、表达式</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E8%AF%AD%E6%B3%95%E6%A0%BC%E5%BC%8F"><span class="nav-text">1. 语法格式</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-%E5%B8%83%E5%B0%94%E8%A1%A8%E8%BE%BE%E5%BC%8F"><span class="nav-text">2. 布尔表达式</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#2-1-%E8%AF%AD%E6%B3%95%E6%A0%BC%E5%BC%8F"><span class="nav-text">2.1 语法格式</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-2-%E4%BD%BF%E7%94%A8%E5%AE%9E%E4%BE%8B"><span class="nav-text">2.2 使用实例</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-%E6%95%B0%E5%80%BC%E8%A1%A8%E8%BE%BE%E5%BC%8F"><span class="nav-text">3. 数值表达式</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#3-1-%E8%AF%AD%E6%B3%95%E6%A0%BC%E5%BC%8F"><span class="nav-text">3.1 语法格式</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-2-%E4%BD%BF%E7%94%A8%E5%AE%9E%E4%BE%8B"><span class="nav-text">3.2 使用实例</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#3-2-1-%E5%AE%9E%E4%BE%8B1"><span class="nav-text">3.2.1 实例1</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#3-2-2-%E5%AE%9E%E4%BE%8B2"><span class="nav-text">3.2.2 实例2</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-%E6%97%A5%E6%9C%9F%E8%A1%A8%E8%BE%BE%E5%BC%8F"><span class="nav-text">4. 日期表达式</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#4-1-%E8%AF%AD%E6%B3%95%E6%A0%BC%E5%BC%8F"><span class="nav-text">4.1 语法格式</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-2-%E4%BD%BF%E7%94%A8%E5%AE%9E%E4%BE%8B"><span class="nav-text">4.2 使用实例</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#4-2-1-%E8%8E%B7%E5%8F%96%E5%BD%93%E5%89%8D%E6%97%B6%E9%97%B4"><span class="nav-text">4.2.1 获取当前时间</span></a></li></ol></li></ol></li></ol></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="苏木"
      src="/images/avatar.jpg">
  <p class="site-author-name" itemprop="name">苏木</p>
  <div class="site-description" itemprop="description">莫道桑榆晚，为霞尚满天</div>
</div>
<div class="site-state-wrap animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
        <a href="/archives/">
          <span class="site-state-item-count">673</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
          <a href="/categories/">
        <span class="site-state-item-count">42</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
        <span class="site-state-item-count">43</span>
        <span class="site-state-item-name">标签</span>
      </div>
  </nav>
</div>
  <div class="links-of-author animated">
      <span class="links-of-author-item">
        <a href="https://github.com/sumumm" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;sumumm" rel="noopener me" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
  </div>

        </div>
      </div>
    </div>

    
  </aside>


    </div>

    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://sumumm.github.io/post/aaf421eb.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.jpg">
      <meta itemprop="name" content="苏木">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="苏木">
      <meta itemprop="description" content="莫道桑榆晚，为霞尚满天">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="LV07-02-SQLite-数据类型、运算符和表达式 | 苏木">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          LV07-02-SQLite-数据类型、运算符和表达式
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2023-07-03 21:30:25" itemprop="dateCreated datePublished" datetime="2023-07-03T21:30:25+08:00">2023-07-03</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/" itemprop="url" rel="index"><span itemprop="name">嵌入式开发</span></a>
        </span>
          ，
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/" itemprop="url" rel="index"><span itemprop="name">01HQ课程体系</span></a>
        </span>
          ，
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV07-SQLite/" itemprop="url" rel="index"><span itemprop="name">LV07-SQLite</span></a>
        </span>
    </span>

  
    <span class="post-meta-break"></span>
    <span class="post-meta-item" title="本文字数">
      <span class="post-meta-item-icon">
        <i class="far fa-file-word"></i>
      </span>
      <span class="post-meta-item-text">本文字数：</span>
      <span>4.6k</span>
    </span>
    <span class="post-meta-item" title="阅读时长">
      <span class="post-meta-item-icon">
        <i class="far fa-clock"></i>
      </span>
      <span class="post-meta-item-text">阅读时长 &asymp;</span>
      <span>17 分钟</span>
    </span>
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody"><p>本文主要是<code>SQLite</code>数据库的数据类型、运算符和表达式相关笔记，若笔记中有错误或者不合适的地方，欢迎批评指正😃。</p>
<span id="more"></span>

<!-- Photo: none -->

<details class="folding-tag" blue><summary> 点击查看使用工具及版本 </summary>
              <div class='content'>
              <table>    <tr>        <td align="center" width=150px>Windows</td>        <td align="left">windows11</td>    </tr>    <tr>        <td align="center">Ubuntu</td>        <td align="left">Ubuntu16.04的64位版本</td>      </tr>    <tr>        <td align="center">VMware® Workstation 16 Pro</td>        <td align="left">16.2.3 build-19376536</td>      </tr>    <tr>        <td align="center">SecureCRT</td>        <td align="left">Version 8.7.2 (x64 build 2214)   -   正式版-2020年5月14日</td>      </tr>    <tr>        <td align="center">开发板</td>        <td align="left">正点原子 i.MX6ULL Linux阿尔法开发板</td>      </tr>    <tr>        <td align="center">uboot</td>        <td align="left">NXP官方提供的uboot，NXP提供的版本为uboot-imx-rel_imx_4.1.15_2.1.0_ga(使用的uboot版本为U-Boot 2016.03)</td>      </tr>    <tr>        <td align="center">linux内核</td>        <td align="left">linux-4.15(NXP官方提供)</td>      </tr>    <tr>        <td align="center">STM32开发板</td>        <td align="left">正点原子战舰V3(STM32F103ZET6)</td>      </tr></table>
              </div>
            </details>

<details class="folding-tag" blue><summary> 点击查看本文参考资料 </summary>
              <div class='content'>
              <table>    <tr><td align="center">参考方向  </td><td align="center">参考原文</td></tr>    <tr><td align="left">SQLite官网</td><td align="left"><a href="https://www.sqlite.org/index.html" target="_blank">SQLite Home Page <i class="fa fa-external-link-alt"></i> </a></td></tr>    <tr><td align="left">SQLite中文网</td><td align="left"><a href="https://www.sqlite.net.cn/" target="_blank">SQLite 中文网 <i class="fa fa-external-link-alt"></i> </a></td></tr>    <tr><td align="left">SQLite 基础教程</td><td align="left"><a href="https://www.php.cn/manual/view/19335.html" target="_blank">SQLite参考手册 - 在线原生手册 <i class="fa fa-external-link-alt"></i> </a></td></tr>    <tr><td align="left">菜鸟教程</td><td align="left"><a href="https://www.runoob.com/sqlite/sqlite-tutorial.html" target="_blank">SQLite 教程 <i class="fa fa-external-link-alt"></i> </a></td></tr>    <tr><td align="left">易百教程</td><td align="left"><a href="https://www.yiibai.com/sqlite" target="_blank">SQLite 教程 <i class="fa fa-external-link-alt"></i> </a></td></tr></table>
              </div>
            </details>

<details class="folding-tag" blue><summary> 点击查看相关文件下载 </summary>
              <div class='content'>
              <table>    <tr>        <td align="center">---</td>        <td align="left">--- <a href="" target="_blank">  <i class="fa fa-external-link-alt"></i></a></td>      </tr></table>
              </div>
            </details>




<h1 id="一、数据类型"><a href="#一、数据类型" class="headerlink" title="一、数据类型"></a><font size=3>一、数据类型</font></h1><p>我们既然要通过数据库来存储数据，自然需要数据类型啦，不然怎么知道这列都存储了什么样的数据呢？</p>
<p><code>SQLite</code> 数据类型是一个用来指定任何对象的数据类型的属性。<code>SQLite</code> 中的每一列，每个变量和表达式都有相关的数据类型。我们可以在创建表的同时使用这些数据类型。<code>SQLite</code> 使用一个更普遍的<strong>动态类型系统</strong>。在 <code>SQLite</code> 中，值的数据类型与值本身是相关的，而不是与它的容器相关。说实话，这段话我并不怎么理解，但是吧，暂时会用就好，哈哈哈，后边懂了再补充。</p>
<h2 id="1-SQLite-存储类"><a href="#1-SQLite-存储类" class="headerlink" title="1. SQLite 存储类"></a><font size=3>1. <code>SQLite</code> 存储类</font></h2><table>
    <tr><td align="center" width=150px>存储类</td><td align="center">描述</td></tr>
    <tr><td align="center" width=150px>NULL</td><td align="left">值是一个 NULL 值。</td></tr>
    <tr><td align="center" width=150px>INTEGER</td><td align="left">值是一个带符号的整数，根据值的大小存储在 1、2、3、4、6 或 8 字节中。</td></tr>
    <tr><td align="center" width=150px>REAL</td><td align="left">值是一个浮点值，存储为 8 字节的 IEEE 浮点数字。</td></tr>
    <tr><td align="center" width=150px>TEXT</td><td align="left">值是一个文本字符串，使用数据库编码（UTF-8、UTF-16BE 或 UTF-16LE）存储。</td></tr>
    <tr><td align="center" width=150px>BLOB</td><td align="left">值是一个 blob 数据，完全根据它的输入存储。</td></tr>
</table>
一个存储类比一个数据类型更加的通用。比如，`INTEGER`存储类包含`6`种不同长度的`integer`数据类型。这使得在磁盘存储上有所差异。但是只要一个`INTEGER`类的值磁盘所读取，它们就会被转换成更加通用的数据类型（`8`进制有符号整型`integer`）。因此，在大多数情况下，“存储类”和“数据类型”无法区分，并且两个属于可以互相转换。

<h2 id="2-SQLite-亲和-Affinity-类型"><a href="#2-SQLite-亲和-Affinity-类型" class="headerlink" title="2. SQLite 亲和(Affinity)类型"></a><font size=3>2. <code>SQLite</code> 亲和(<code>Affinity</code>)类型</font></h2><h3 id="2-1-什么是亲和类型？"><a href="#2-1-什么是亲和类型？" class="headerlink" title="2.1 什么是亲和类型？"></a><font size=3>2.1 什么是亲和类型？</font></h3><p><code>SQLite</code><strong>不强制数据类型约束</strong>，也就是说任何数据都可以插入任何列。例如，我们可以向一个整型列中插入任意长度的字符串，向布尔型列中插入浮点数，或者向字符型列中插入日期型值。</p>
<p>在创建数据表时所指定的数据类型不会限制在该列中插入任何数据。任何列均可接受任意长度的字符串（只有一种情况除外，就是标志为<code>INTEGER PRIMARY KEY</code>的列只能存储<code>64</code>位整数， 当向这种列中插数据除整数以外的数据时，将会产生错误。）</p>
<p><code>SQLite</code>确实使用声明的列类型来指示我们所期望的格式。所以，当我们向一个整型列中插入字符串时，<code>SQLite</code>会试图将该字符串转换成一个整数。如果可以转换，它将插入该整数；否则，将插入字符串。这是一个特性，而不是一个<code>bug</code>。这种特性被称为<strong>列亲和性</strong>(<code>type or column affinity</code>).</p>
<p>而<strong>列的亲和类型是指该列数据的推荐类型</strong>。需要注意，这个类型只是推荐的，而不是必须的。上边已经说过任何列可以存储任何类型的数据，只是说根据选择，某些列更倾向于使用一个存储类型而不是另一个存储类型。</p>
<h3 id="2-2-SQLite支持的亲和类型"><a href="#2-2-SQLite支持的亲和类型" class="headerlink" title="2.2 SQLite支持的亲和类型"></a><font size=3>2.2 <code>SQLite</code>支持的亲和类型</font></h3><p>上边我们知道了<code>SQLite</code>支持列的类型近似性。列可以存储任何类型的数据，而列的首选存储类称为它的近似性类型。在<code>SQLite3</code>数据库中有以下类型近似可用于分配：</p>
<table>
    <tr><td align="center" width=120px>亲和类型</td><td align="center">描述</td></tr>
    <tr><td align="center" width=120px>TEXT    </td><td align="left">数值型数据在被插入之前，需要先被转换为文本格式，之后再插入到目标字段中。</td></tr>
    <tr><td align="center" width=120px>NUMERIC </td><td align="left">当文本数据被插入到亲缘性为NUMERIC的字段中时，如果转换操作不会导致数据信息丢失以及完全可逆，那么SQLite就会将该文本数据转换为INTEGER或REAL类型的数据，如果转换失败，SQLite仍会以TEXT方式存储该数据。对于NULL或BLOB类型的新数据，SQLite将不做任何转换，直接以NULL或BLOB的方式存储该数据。需要额外说明的是，对于浮点格式的常量文本，如"30000.0"，如果该值可以转换为INTEGER同时又不会丢失数值信息，那么SQLite就会将其转换为INTEGER的存储方式。</td></tr>
    <tr><td align="center" width=120px>INTEGER </td><td align="left">对于亲缘类型为INTEGER的字段，其规则等同于NUMERIC，唯一差别是在执行CAST表达式时。</td></tr>
    <tr><td align="center" width=120px>REAL    </td><td align="left">其规则基本等同于NUMERIC，唯一的差别是不会将"30000.0"这样的文本数据转换为INTEGER存储方式。</td></tr>
    <tr><td align="center" width=120px>NONE    </td><td align="left">不做任何的转换，直接以该数据所属的数据类型进行存储。</td></tr>
</table>
## <font size=3>3. `SQLite` 亲和类型(`Affinity`)及类型名称</font>

<p>当创建 <code>SQLite3</code> 表时可使用的各种数据类型名称，同时也显示了相应的亲和类型：</p>
<table>
    <tr><td align="center" width=150px>亲和类型</td><td align="center">数据类型</td></tr>
    <tr><td align="center" width=150px>INTEGER </td><td align="left">INT, INTEGER, TINYINT, SMALLINT, MEDIUMINT, BIGINT, UNSIGNED BIG INT, INT2, INT8</td></tr>
    <tr><td align="center" width=150px>TEXT    </td><td align="left">CHARACTER(20), VARCHAR(255), VARYING CHARACTER(255), NCHAR(55), NATIVE CHARACTER(70), NVARCHAR(100), TEXT, CLOB</td></tr>
    <tr><td align="center" width=150px>NONE    </td><td align="left">BLOB, no datatype specified</td></tr>
    <tr><td align="center" width=150px>REAL    </td><td align="left">REAL, DOUBLE, DOUBLE PRECISION, FLOAT</td></tr>
    <tr><td align="center" width=150px>NUMERIC </td><td align="left">NUMERIC, DECIMAL(10,5), BOOLEAN, DATE, DATETIME</td></tr>
</table>

<h1 id="二、运算符"><a href="#二、运算符" class="headerlink" title="二、运算符"></a><font size=3>二、运算符</font></h1><p>运算符用于指定 <code>SQLite</code> 语句中的条件，并在语句中连接多个条件。常用于<code>where</code>子句中，以便于对指定数据记录执行相关操作。<code>SQlite</code>中的运算符主要有<strong>算术运算符</strong>、<strong>比较运算符</strong>、<strong>逻辑运算符</strong>和<strong>位运算符</strong>。</p>
<h2 id="1-算术运算符"><a href="#1-算术运算符" class="headerlink" title="1. 算术运算符"></a><font size=3>1. 算术运算符</font></h2><p>假设变量 <code>a=10</code>，变量 <code>b=20</code>，则：</p>
<table>
    <tr><td align="center">运算符</td><td align="center">说明</td><td align="left">示例</td></tr>
    <tr><td align="center">+</td><td align="left">加法运算符：用于将运算符两侧的值相加。</td><td align="left">a+b = 50</td></tr>
    <tr><td align="center">-</td><td align="left">减法运算符：用于从左操作数减去右操作数。</td><td align="left">a-b = -10</td></tr>
    <tr><td align="center">*</td><td align="left">乘法运算符：用于将运算符两边的操作数相乘。</td><td align="left">a*b = 200</td></tr>
    <tr><td align="center">/</td><td align="left">除法运算符：它是将左操作数除以右操作数。</td><td align="left">b/a = 2</td></tr>
    <tr><td align="center">%</td><td align="left">取模运算符：用于通过左操作数除以右操作数并返回余数。</td><td align="left">b%a = 0</td></tr>
</table>

<h2 id="2-比较运算符"><a href="#2-比较运算符" class="headerlink" title="2. 比较运算符"></a><font size=3>2. 比较运算符</font></h2><p>假设变量 <code>a=10</code>，变量 <code>b=20</code>，则：</p>
<table>
    <tr><td align="center" width=100px>运算符</td><td align="center">描述</td><td align="center">实例</td></tr>
    <tr><td align="center" width=100px>==</td><td align="left">检查两个操作数的值是否相等，如果相等则返回true,否则返回false。</td><td align="left">(a == b) 不为真。</td></tr>
    <tr><td align="center" width=100px>=</td><td align="left">检查两个操作数的值是否相等，如果相等则返回true,否则返回false。</td><td align="left">(a = b) 不为真。 </td></tr>
    <tr><td align="center" width=100px>!=</td><td align="left">检查两个操作数的值是否不相等，如果不相等则返回true,否则返回false。</td><td align="left">(a != b) 为真。  </td></tr>
    <tr><td align="center" width=100px>&lt;&gt;</td><td align="left">检查两个操作数的值是否不相等，如果不相等则返回true,否则返回false。</td><td align="left">(a &lt;&gt; b) 为真。</td></tr>
    <tr><td align="center" width=100px>&gt;</td><td align="left">检查左操作数的值是否大于右操作数的值，如果是则返回true,否则返回false。</td><td align="left">(a &gt; b) 不为真。 </td></tr>
    <tr><td align="center" width=100px>&lt;</td><td align="left">检查左操作数的值是否小于右操作数的值，如果是则返回true,否则返回false。</td><td align="left">(a &lt; b) 为真。</td></tr>
    <tr><td align="center" width=100px>&gt;=</td><td align="left">检查左操作数的值是否大于等于右操作数的值，如果是则返回true,否则返回false。</td><td align="left">(a &gt;= b) 不为真。</td></tr>
    <tr><td align="center" width=100px>&lt;=</td><td align="left">检查左操作数的值是否小于等于右操作数的值，如果是则返回true,否则返回false。</td><td align="left">(a &lt;= b) 为真。</td></tr>
    <tr><td align="center" width=100px>!&lt;</td><td align="left">检查左操作数的值是否不小于(大于等于)右操作数的值，如果是则返回true,否则返回false。 </td><td align="left">(a !&lt; b) 为假。</td></tr>
    <tr><td align="center" width=100px>!&gt;</td><td align="left">检查左操作数的值是否不大于(小于等于)右操作数的值，如果是则返回true,否则返回false。</td><td align="left">(a !&gt; b) 为真。</td></tr>
</table>

<h2 id="3-逻辑运算符"><a href="#3-逻辑运算符" class="headerlink" title="3. 逻辑运算符"></a><font size=3>3. 逻辑运算符</font></h2><table>
    <tr><td align="center" width=150px>运算符 </td><td align="center"> 描述</td></tr>
    <tr><td align="center" width=150px>AND</td><td align="left"> AND 运算符允许在一个 SQL 语句的 WHERE 子句中的多个条件的存在。</td></tr>
    <tr><td align="center" width=150px>BETWEEN</td><td align="left"> BETWEEN 运算符用于在给定最小值和最大值范围内的一系列值中搜索值。</td></tr>
    <tr><td align="center" width=150px>EXISTS </td><td align="left"> EXISTS 运算符用于在满足一定条件的指定表中搜索行的存在。</td></tr>
    <tr><td align="center" width=150px>IN</td><td align="left"> IN 运算符用于把某个值与一系列指定列表的值进行比较。</td></tr>
    <tr><td align="center" width=150px>NOT IN </td><td align="left"> IN 运算符的对立面，用于把某个值与不在一系列指定列表的值进行比较。</td></tr>
    <tr><td align="center" width=150px>LIKE</td><td align="left"> LIKE 运算符用于把某个值与使用通配符运算符的相似值进行比较。</td></tr>
    <tr><td align="center" width=150px>GLOB</td><td align="left"> GLOB 运算符用于把某个值与使用通配符运算符的相似值进行比较。GLOB 与 LIKE 不同之处在于，它是大小写敏感的。</td></tr>
    <tr><td align="center" width=150px>NOT</td><td align="left"> NOT 运算符是所用的逻辑运算符的对立面。比如 NOT EXISTS、NOT BETWEEN、NOT IN，等等。它是否定运算符。</td></tr>
    <tr><td align="center" width=150px>OR</td><td align="left"> OR 运算符用于结合一个 SQL 语句的 WHERE 子句中的多个条件</td></tr>
    <tr><td align="center" width=150px>IS NULL</td><td align="left"> NULL 运算符用于把某个值与 NULL 值进行比较。</td></tr>
    <tr><td align="center" width=150px>IS</td><td align="left"> IS 运算符与 = 相似。</td></tr>
    <tr><td align="center" width=150px>IS NOT </td><td align="left"> IS NOT 运算符与 != 相似。</td></tr>
    <tr><td align="center" width=150px>||</td><td align="left"> 连接两个不同的字符串，得到一个新的字符串。</td></tr>
    <tr><td align="center" width=150px>UNIQUE</td><td align="left"> UNIQUE 运算符搜索指定表中的每一行，确保唯一性（无重复）。</td></tr>
</table>

<h2 id="4-位运算符"><a href="#4-位运算符" class="headerlink" title="4. 位运算符"></a><font size=3>4. 位运算符</font></h2><h3 id="4-1-一个真值表"><a href="#4-1-一个真值表" class="headerlink" title="4.1 一个真值表"></a><font size=3>4.1 一个真值表</font></h3><p>位运算符作用于位，并逐位执行操作。真值表 <code>&amp;</code> 和 <code>|</code> 如下：</p>
<table>
    <tr><td align="center">p</td><td align="center">q</td><td align="center">p & q</td><td align="center">p | q</td></tr>
    <tr><td align="center">0</td><td align="center">0</td><td align="center">0</td><td align="center">0</td></tr>
    <tr><td align="center">0</td><td align="center">1</td><td align="center">0</td><td align="center">1</td></tr>
    <tr><td align="center">1</td><td align="center">1</td><td align="center">1</td><td align="center">1</td></tr>
    <tr><td align="center">1</td><td align="center">0</td><td align="center">0</td><td align="center">1</td></tr>
</table>

<h3 id="4-2-运算符说明"><a href="#4-2-运算符说明" class="headerlink" title="4.2 运算符说明"></a><font size=3>4.2 运算符说明</font></h3><p>假设变量 <code>A=60(0011 1100)</code>，变量 <code>B=13(0000 1101)</code>，则：</p>
<table>
    <tr><td align="center" width=150px>运算符</td><td align="left">描述</td><td align="left">实例 </td></tr>
    <tr><td align="center" width=150px>&</td><td align="left">如果同时存在于两个操作数中，二进制 AND 运算符复制一位到结果中。</td><td align="left">(A & B) 将得到 12，即为 0000 1100</td></tr>
    <tr><td align="center" width=150px>|</td><td align="left">如果存在于任一操作数中，二进制 OR 运算符复制一位到结果中。</td><td align="left">(A \| B) 将得到 61，即为 0011 1101</td></tr>
    <tr><td align="center" width=150px>~</td><td align="left">二进制补码运算符是一元运算符，具有"翻转"位效应，即0变成1，1变成0。</td><td align="left">(~A ) 将得到 -61，即为 1100 0011，一个有符号二进制数的补码形式。</td></tr>
    <tr><td align="center" width=150px>&lt;&lt;</td><td align="left">二进制左移运算符。左操作数的值向左移动右操作数指定的位数。</td><td align="left">A &lt;&lt; 2 将得到 240，即为 1111 0000</td></tr>
    <tr><td align="center" width=150px>&gt;&gt;</td><td align="left">二进制右移运算符。左操作数的值向右移动右操作数指定的位数。</td><td align="left">A &gt;&gt; 2 将得到 15，即为 0000 1111</td></tr> 
</table>

<h1 id="三、表达式"><a href="#三、表达式" class="headerlink" title="三、表达式"></a><font size=3>三、表达式</font></h1><p>表达式是一个或多个值、运算符和计算值的<code>SQL</code>函数的组合。<code>SQL</code> 表达式与公式类似，都写在查询语言中，我们还可以使用特定的数据集来查询数据库。</p>
<h2 id="1-语法格式"><a href="#1-语法格式" class="headerlink" title="1. 语法格式"></a><font size=3>1. 语法格式</font></h2><p><code>SQLite</code>表达式用查询语言(<code>SQL</code>)编写，并与<code>SELECT</code>（后边会详细学习）语句一起使用。一般语法格式如下：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">-- 多行语句</span><br><span class="line">SELECT column1, column2, columnN   </span><br><span class="line">FROM table_name   </span><br><span class="line">WHERE [CONDITION | EXPRESSION];</span><br><span class="line"></span><br><span class="line">-- 单行语句</span><br><span class="line">SELECT column1, column2, columnN FROM table_name WHERE [CONDITION | EXPRESSION];</span><br></pre></td></tr></table></figure>

<p><strong>【注意】</strong></p>
<p>（1）写成小写也是可以的。</p>
<p>（2）关于<code>SELECT</code>和<code>WHERE</code>后边会详细学习，这里就简单了解就好啦。</p>
<h2 id="2-布尔表达式"><a href="#2-布尔表达式" class="headerlink" title="2. 布尔表达式"></a><font size=3>2. 布尔表达式</font></h2><h3 id="2-1-语法格式"><a href="#2-1-语法格式" class="headerlink" title="2.1 语法格式"></a><font size=3>2.1 语法格式</font></h3><p>一般语法格式如下：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">SELECT column1, column2, columnN   </span><br><span class="line">FROM table_name   </span><br><span class="line">WHERE SINGLE VALUE MATCHTING EXPRESSION;</span><br></pre></td></tr></table></figure>

<h3 id="2-2-使用实例"><a href="#2-2-使用实例" class="headerlink" title="2.2 使用实例"></a><font size=3>2.2 使用实例</font></h3><p>假设 <code>COMPANY</code> 表有以下记录：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">ID          NAME        AGE         ADDRESS     SALARY</span><br><span class="line">----------  ----------  ----------  ----------  ----------</span><br><span class="line">1           Paul        32          California  20000.0</span><br><span class="line">2           Allen       25          Texas       15000.0</span><br><span class="line">3           Teddy       23          Norway      20000.0</span><br><span class="line">4           Mark        25          Rich-Mond   65000.0</span><br><span class="line">5           David       27          Texas       85000.0</span><br><span class="line">6           Kim         22          South-Hall  45000.0</span><br><span class="line">7           James       24          Houston     10000.0</span><br></pre></td></tr></table></figure>

<p>在<code>SQLite</code>命令提示符中输入以下语句：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sqlite&gt; SELECT * FROM COMPANY WHERE SALARY = 10000;</span><br></pre></td></tr></table></figure>

<p>则会看到如下输出（默认的输出可不是这样的格式，后边学习到<code>SQLite</code>命令的时候就会了解到如何设置成这样的显示格式啦）：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">ID          NAME        AGE         ADDRESS     SALARY</span><br><span class="line">----------  ----------  ----------  ----------  ----------</span><br><span class="line">4           James        24          Houston   10000.0</span><br></pre></td></tr></table></figure>

<h2 id="3-数值表达式"><a href="#3-数值表达式" class="headerlink" title="3. 数值表达式"></a><font size=3>3. 数值表达式</font></h2><h3 id="3-1-语法格式"><a href="#3-1-语法格式" class="headerlink" title="3.1 语法格式"></a><font size=3>3.1 语法格式</font></h3><p>一般语法格式如下：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">SELECT numerical_expression as  OPERATION_NAME</span><br><span class="line">[FROM table_name WHERE CONDITION] ;</span><br></pre></td></tr></table></figure>

<ul>
<li><code>numerical_expression</code> ：用于数学表达式或任何公式。</li>
</ul>
<h3 id="3-2-使用实例"><a href="#3-2-使用实例" class="headerlink" title="3.2 使用实例"></a><font size=3>3.2 使用实例</font></h3><h4 id="3-2-1-实例1"><a href="#3-2-1-实例1" class="headerlink" title="3.2.1 实例1"></a><font size=3>3.2.1 实例1</font></h4><p>在<code>SQLite</code>命令提示符中输入以下语句：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">sqlite&gt; SELECT (15 + 6) AS ADDITION;</span><br><span class="line">ADDITION = 21</span><br></pre></td></tr></table></figure>

<h4 id="3-2-2-实例2"><a href="#3-2-2-实例2" class="headerlink" title="3.2.2 实例2"></a><font size=3>3.2.2 实例2</font></h4><p>有几个内置的函数，比如 <code>avg()</code>、<code>sum()</code>、<code>count()</code>，等等，执行被称为对一个表或一个特定的表列的汇总数据计算。例如，</p>
<p>假设 <code>COMPANY</code> 表有以下记录：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">ID          NAME        AGE         ADDRESS     SALARY</span><br><span class="line">----------  ----------  ----------  ----------  ----------</span><br><span class="line">1           Paul        32          California  20000.0</span><br><span class="line">2           Allen       25          Texas       15000.0</span><br><span class="line">3           Teddy       23          Norway      20000.0</span><br><span class="line">4           Mark        25          Rich-Mond   65000.0</span><br><span class="line">5           David       27          Texas       85000.0</span><br><span class="line">6           Kim         22          South-Hall  45000.0</span><br><span class="line">7           James       24          Houston     10000.0</span><br></pre></td></tr></table></figure>

<p>在<code>SQLite</code>命令提示符中输入以下语句：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">sqlite&gt; SELECT COUNT(*) AS &quot;RECORDS&quot; FROM COMPANY; </span><br><span class="line">RECORDS = 7</span><br></pre></td></tr></table></figure>

<h2 id="4-日期表达式"><a href="#4-日期表达式" class="headerlink" title="4. 日期表达式"></a><font size=3>4. 日期表达式</font></h2><p>日期表达式返回当前系统日期和时间值，这些表达式可以被用于各种数据操作。</p>
<h3 id="4-1-语法格式"><a href="#4-1-语法格式" class="headerlink" title="4.1 语法格式"></a><font size=3>4.1 语法格式</font></h3><p>这里的话似乎没什么固定的语法格式，直接看实例把</p>
<h3 id="4-2-使用实例"><a href="#4-2-使用实例" class="headerlink" title="4.2 使用实例"></a><font size=3>4.2 使用实例</font></h3><h4 id="4-2-1-获取当前时间"><a href="#4-2-1-获取当前时间" class="headerlink" title="4.2.1 获取当前时间"></a><font size=3>4.2.1 获取当前时间</font></h4><p>在<code>SQLite</code>命令提示符中输入以下语句：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">sqlite&gt; SELECT datetime(&#x27;now&#x27;,&#x27;localtime&#x27;);</span><br><span class="line">2022-07-20 07:29:05</span><br></pre></td></tr></table></figure>


    </div>

    
    
    

    <footer class="post-footer">




    <div>
        
            <div style="text-align:center;color: #ccc;font-size:14px;">
            ----------本文结束
            <i class="fas fa-fan fa-spin" style="color: #FF1493; font-size: 1rem"></i>
            感谢您的阅读----------
            </div>
        
    </div>





  
  <div class="my_post_copyright"> 
    <p><span>文章标题:</span><a href="/post/aaf421eb.html">LV07-02-SQLite-数据类型、运算符和表达式</a></p>
    <p><span>文章作者:</span><a href="/" title="欢迎访问 《苏木》 的学习笔记">苏木</a></p>
    <p><span>发布时间:</span>2023年07月03日 - 21:30</p>
    <p><span>最后更新:</span>2025年06月14日 - 00:25</p>
    <p><span>原始链接:</span><a href="/post/aaf421eb.html" title="LV07-02-SQLite-数据类型、运算符和表达式">https://sumumm.github.io/post/aaf421eb.html</a></p>
    <p><span>许可协议:</span><i class="fab fa-creative-commons"></i> <a rel="license" href= "https://creativecommons.org/licenses/by-nc-nd/4.0/" target="_blank" title="Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0)">署名-非商业性使用-禁止演绎 4.0 国际</a> 转载请保留原文链接及作者。</p>  
  </div>
  


          <div class="post-tags">
              <a href="/tags/LV07-SQLite/" rel="tag"><i class="fa fa-tag"></i> LV07-SQLite</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/post/6540bbef.html" rel="prev" title="LV07-03-SQLite-语句">
                  <i class="fa fa-angle-left"></i> LV07-03-SQLite-语句
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/post/84248a27.html" rel="next" title="LV07-01-SQLite-基础知识">
                  LV07-01-SQLite-基础知识 <i class="fa fa-angle-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>






</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">

  <div class="copyright">
    &copy; 2017 – 
    <span itemprop="copyrightYear">2025</span>
    <span class="with-love">
      <i class="fa fa-heart"></i>
    </span>
    <span class="author" itemprop="copyrightHolder">苏木</span>
  </div>
<div class="wordcount">
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-line"></i>
    </span>
      <span>站点总字数：</span>
    <span title="站点总字数">3.7m</span>
  </span>
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
      <span>站点阅读时长 &asymp;</span>
    <span title="站点阅读时长">225:26</span>
  </span>
</div>




    <span id="sitetime"></span>
    <script defer language=javascript>
        function siteTime()
        {
            window.setTimeout("siteTime()", 1000);
            var seconds = 1000;
            var minutes = seconds * 60;
            var hours = minutes * 60;
            var days = hours * 24;
            var years = days * 365;
            var today = new Date();
            var todayYear = today.getFullYear();
            var todayMonth = today.getMonth()+1;
            var todayDate = today.getDate();
            var todayHour = today.getHours();
            var todayMinute = today.getMinutes();
            var todaySecond = today.getSeconds();
            /*==================================================
            Date.UTC() -- 返回date对象距世界标准时间(UTC)1970年1月1日午夜之间的毫秒数(时间戳)
            year        - 作为date对象的年份，为4位年份值
            month       - 0-11之间的整数，做为date对象的月份
            day         - 1-31之间的整数，做为date对象的天数
            hours       - 0(午夜24点)-23之间的整数，做为date对象的小时数
            minutes     - 0-59之间的整数，做为date对象的分钟数
            seconds     - 0-59之间的整数，做为date对象的秒数
            microseconds - 0-999之间的整数，做为date对象的毫秒数
            ==================================================*/
            var t1 = Date.UTC(2017, 
                              5, 
                              19, 
                              0, 
                              0, 
                              0); //北京时间
            var t2 = Date.UTC(todayYear,todayMonth,todayDate,todayHour,todayMinute,todaySecond);
            var diff = t2-t1;
            var diffYears = Math.floor(diff/years);
            var diffDays = Math.floor((diff/days)-diffYears*365);
            var diffHours = Math.floor((diff-(diffYears*365+diffDays)*days)/hours);
            var diffMinutes = Math.floor((diff-(diffYears*365+diffDays)*days-diffHours*hours)/minutes);
            var diffSeconds = Math.floor((diff-(diffYears*365+diffDays)*days-diffHours*hours-diffMinutes*minutes)/seconds);
            document.getElementById("sitetime").innerHTML="已在这里 "+diffYears+" 年 "+diffDays+" 天 "+diffHours+" 小时 "+diffMinutes+" 分钟 "+diffSeconds+" 秒";
        }
        siteTime();
    </script>



    </div>
  </footer>

  
  <div class="back-to-top" role="button" aria-label="返回顶部">
    <i class="fa fa-arrow-up fa-lg"></i>
    <span>0%</span>
  </div>
  <div class="reading-progress-bar"></div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


  
  <script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.1/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/next-theme-pjax/0.6.0/pjax.min.js" integrity="sha256-vxLn1tSKWD4dqbMRyv940UYw4sXgMtYcK6reefzZrao=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/fancyapps-ui/5.0.28/fancybox/fancybox.umd.js" integrity="sha256-ytMJGN3toR+a84u7g7NuHm91VIR06Q41kMWDr2pq7Zo=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/lozad.js/1.16.0/lozad.min.js" integrity="sha256-mOFREFhqmHeQbXpK2lp4nA3qooVgACfh88fpJftLBbc=" crossorigin="anonymous"></script>
<script src="/js/comments.js"></script><script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/next-boot.js"></script><script src="/js/pjax.js"></script>

  <script src="https://cdnjs.cloudflare.com/ajax/libs/hexo-generator-searchdb/1.4.1/search.js" integrity="sha256-1kfA5uHPf65M5cphT2dvymhkuyHPQp5A53EGZOnOLmc=" crossorigin="anonymous"></script>
<script src="/js/third-party/search/local-search.js"></script>




  <script src="/js/third-party/fancybox.js"></script>

  <script src="/js/third-party/pace.js"></script>


  




  

  <script class="next-config" data-name="enableMath" type="application/json">true</script><script class="next-config" data-name="mathjax" type="application/json">{"enable":true,"tags":"none","js":{"url":"https://cdnjs.cloudflare.com/ajax/libs/mathjax/3.2.2/es5/tex-mml-chtml.js","integrity":"sha256-MASABpB4tYktI2Oitl4t+78w/lyA+D7b/s9GEP0JOGI="}}</script>
<script src="/js/third-party/math/mathjax.js"></script>


 
        <div id="click-show-text"
            data-mobile = false
            data-text = 富强,民主,文明,和谐,自由,平等,公正,法制,爱国,敬业,诚信,友善
            data-fontsize = 15px
            data-random= false>
        </div>
       

      
        <script async src=https://cdn.jsdelivr.net/npm/hexo-next-mouse-effect@latest/click/showText.js></script>
      

      
    




    <script async src="/js/fancybox_param.js"></script>





<!-- APlayer本体 -->



</body>
</html>
